package de.bremen.bremenbybike.coordinates;

import java.text.DecimalFormat;

/**
 * A geographic position with latitude, longitude, and altitude.
 * 
 */
public final class GeographicCoordinate {
    /*
     * consts
     */
    private static final DecimalFormat decFormat = new DecimalFormat("#.00000");

    /*
     * members
     */
    /**
     * the latitude
     */
    public double latitude;
    /**
     * the longitude
     */
    public double longitude;
    /**
     * the altitude
     */
    public double altitude;

    /*
     * getters & setters
     */
    /**
     * Set the latitude, longitude, and altitude.
     * 
     * @param latitude
     *            the latitude
     * @param longitude
     *            the longitude
     * @param altitude
     *            the altitude
     */
    public final void set(double latitude, double longitude, double altitude) {
        this.latitude = latitude;
        this.longitude = longitude;
        this.altitude = altitude;
    }

    /*
     * ctors
     */
    /**
     * Creates a position with latitude = longitude = altitude = 0.
     */
    public GeographicCoordinate() {
        this(0, 0, 0);
    }

    /**
     * Creates a position with the given values.
     * 
     * @param latitude
     *            the latitude
     * @param longitude
     *            the longitude
     * @param altitude
     *            the altitude
     */
    public GeographicCoordinate(double latitude, double longitude, double altitude) {
        this.latitude = latitude;
        this.longitude = longitude;
        this.altitude = altitude;
    }

    /**
     * Creates a position based on a given one.
     * 
     * @param position
     *            the position
     */
    public GeographicCoordinate(GeographicCoordinate position) {
        this.latitude = position.latitude;
        this.longitude = position.longitude;
        this.altitude = position.altitude;
    }

    /*
     * methods
     */

    /**
     * Copies the position members to another position.
     * 
     * @param position
     *            the position to which the members are copied
     */
    public final void copyMembers(GeographicCoordinate position) {
        position.latitude = this.latitude;
        position.longitude = this.longitude;
        position.altitude = this.altitude;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(Object o) {
        if(o == null)
            return false;

        if(o == this)
            return true;

        if(!o.getClass().equals(getClass()))
            return false;

        GeographicCoordinate position = (GeographicCoordinate)o;
        return this.latitude == position.latitude && this.longitude == position.longitude && this.altitude == position.altitude;
    }


    /**
     * {@inheritDoc}
     */
    @Override
    public final String toString() {
        return decFormat.format(latitude) + ", " + decFormat.format(longitude) + ", " + decFormat.format(altitude);
    }
}